package kr.hkit.powerjava.chapter12.work;

public class Stack implements Structure{
	private String[] arr;
	private int top;
	private int size;
	
	public Stack() {}
	public Stack(int size) {
		this.size = size;
		arr = new String[size];
		top = -1;
	}
	public String[] getArr() {
		return arr;
	}
	public void setArr(String[] arr) {
		this.arr = arr;
	}
	public int getTop() {
		return top;
	}
	public void setTop(int top) {
		this.top = top;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	
	@Override
	public void push(String s) {
		if(isFull() == true) {
			System.out.println("Stack is Full!");
			System.out.println("top : "+top+"\n");
		} else {
			arr[++top] = s;
		}
	}
	
	@Override
	public String pop() {
		if(isEmpty() == true) {
			System.out.println("Stack is Empty!");
			System.out.println("top : "+top);
			return " ";
		} else {
			String s = arr[top];
			arr[top--] = null;
			System.out.println("Pop "+s+" !");
			return s;
		}
	}
	
	@Override
	public boolean isEmpty() {
		return top == -1;
	}
	
	@Override
	public boolean isFull() {
		return top == size-1 ;
	}
	
	@Override
	public void prnStructure() {
		System.out.println("******Stack******");
		for(int i = arr.length-1; i >= 0; i--) {		
			System.out.println("==================");
			System.out.println(arr[i]+ "		"+i);
		}
		System.out.println("==================");
		System.out.println("top : "+top);
		System.out.println("==================");
		System.out.println();
	}

}
